package org.mozilla.intl.chardet;

public class nsEUCSampler
{
  int mTotal = 0;
  int mThreshold = 200;
  int mState = 0;
  public int[] mFirstByteCnt = new int[94];
  public int[] mSecondByteCnt = new int[94];
  public float[] mFirstByteFreq = new float[94];
  public float[] mSecondByteFreq = new float[94];

  public nsEUCSampler()
  {
    Reset();
  }

  public void Reset()
  {
    this.mTotal = 0;
    this.mState = 0;
    for (int i = 0; i < 94; i++)
    {
      int tmp26_25 = 0;
      this.mSecondByteCnt[i] = tmp26_25;
      this.mFirstByteCnt[i] = tmp26_25;
    }
  }

  boolean EnoughData()
  {
    return this.mTotal > this.mThreshold;
  }

  boolean GetSomeData()
  {
    return this.mTotal > 1;
  }

  boolean Sample(byte[] paramArrayOfByte, int paramInt)
  {
    if (this.mState == 1)
      return false;
    int i = 0;
    int j = 0;
    while ((j < paramInt) && (1 != this.mState))
    {
      switch (this.mState)
      {
      case 0:
        if ((paramArrayOfByte[i] & 0x80) != 0)
          if ((255 == (0xFF & paramArrayOfByte[i])) || (161 > (0xFF & paramArrayOfByte[i])))
          {
            this.mState = 1;
          }
          else
          {
            this.mTotal += 1;
            this.mFirstByteCnt[((0xFF & paramArrayOfByte[i]) - 161)] += 1;
            this.mState = 2;
          }
        break;
      case 1:
        break;
      case 2:
        if ((paramArrayOfByte[i] & 0x80) != 0)
        {
          if ((255 == (0xFF & paramArrayOfByte[i])) || (161 > (0xFF & paramArrayOfByte[i])))
          {
            this.mState = 1;
          }
          else
          {
            this.mTotal += 1;
            this.mSecondByteCnt[((0xFF & paramArrayOfByte[i]) - 161)] += 1;
            this.mState = 0;
          }
        }
        else
          this.mState = 1;
        break;
      default:
        this.mState = 1;
      }
      j++;
      i++;
    }
    return 1 != this.mState;
  }

  void CalFreq()
  {
    for (int i = 0; i < 94; i++)
    {
      this.mFirstByteFreq[i] = (this.mFirstByteCnt[i] / this.mTotal);
      this.mSecondByteFreq[i] = (this.mSecondByteCnt[i] / this.mTotal);
    }
  }

  float GetScore(float[] paramArrayOfFloat1, float paramFloat1, float[] paramArrayOfFloat2, float paramFloat2)
  {
    return paramFloat1 * GetScore(paramArrayOfFloat1, this.mFirstByteFreq) + paramFloat2 * GetScore(paramArrayOfFloat2, this.mSecondByteFreq);
  }

  float GetScore(float[] paramArrayOfFloat1, float[] paramArrayOfFloat2)
  {
    float f2 = 0.0F;
    for (int i = 0; i < 94; i++)
    {
      float f1 = paramArrayOfFloat1[i] - paramArrayOfFloat2[i];
      f2 += f1 * f1;
    }
    return (float)Math.sqrt(f2) / 94.0F;
  }
}

/* Location:           D:\soft\chardet.jar
 * Qualified Name:     org.mozilla.intl.chardet.nsEUCSampler
 * JD-Core Version:    0.6.1
 */